import Vue from 'vue'
import VueRouter from 'vue-router'
import Homepage from '../views/Homepage.vue'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [
  {
    path: '/',
    redirect:'/Homepage'//暂时以填报页为主页
  },
  
  {
    path:'/home',
    name:'Home',
    component: () => import(/* webpackChunkName: "home" */ '../views/Home.vue'),
    children:[
       {
          path:'/nonepage',
          name:'Nonepage',
          component: ()=> import(/* webpackChunkName: "nonepage" */ '../views/nonepage.vue'),
        },
      {
        path:'/Homepage',
        name:'Homepage',
        component: ()=>import(/* webpackChunkName: "informationfilling" */ '../views/Homepage.vue'),
        children:[
          {
            path:'/RegistrationInformation',
            component:()=>import(/* webpackChunkName: "RegistrationInformation" */ '../views/HomePageContent/RegistrationInformation.vue')
          },
          {
            path:'/videoCenter',
            component:()=>import(/* webpackChunkName: "videoCenter" */ '../views/HomePageContent/VideoCenter.vue')
          },
        ]
      },
      {
        path:'/login',
        name:'login',
        component: ()=>import(/* webpackChunkName: "login" */ '../views/login.vue')
      },
      {
        path:'/register',
        name:'register',
        component: ()=>import(/* webpackChunkName: "register" */ '../views/register.vue')
      },
      {
        path:'/people',
        name:'people',
        component: ()=>import(/* webpackChunkName: "people" */ '../views/people.vue')
      },
	  {
	    path:'/changepassword',
	    name:'changepassword',
	    component: ()=>import(/* webpackChunkName: "people" */ '../views/changepassword.vue')
	  },
      // {
      //   path:'/changeProvince',
      //   name:'changeProvince',
      //   component: ()=>import(/* webpackChunkName: "people" */ '../views/changeProvince.vue')
      // },
      {
        path:'/informationfilling',
        name:'Informationfilling',
        component: ()=>import(/* webpackChunkName: "informationfilling" */ '../views/InformationFilling.vue')
      },
      // {
      //   path:'/informationfilling',
      //   name:'Informationfilling',
      //   component: ()=>import(/* webpackChunkName: "informationfilling" */ '../views/InformationFilling.vue')
      // },
      {
        path:'/Preparationforfilling',
        name:'Preparationforfilling',
        component: ()=>import(/* webpackChunkName: "informationfilling" */ '../views/Preparationforfilling.vue')
      },
      {
        path:'/voluntarymenu',
        name:'Voluntarymenu',
        component: ()=>import(/* webpackChunkName: "voluntarymenu" */ '../views/VoluntaryMenu.vue')
      },
      {
        path:'/amount',
        name:'Amount',
        component: ()=>import(/* webpackChunkName: "amount" */ '../views/Amount.vue')
      },
      {
        path:'/basicvoluntary',
        name:'Basicvoluntary',
        component: ()=>import(/* webpackChunkName: "basicvoluntary" */ '../views/BasicVoluntary.vue')
      },
      {
        path:'/voluntarygroup',
        name:'Voluntarygroup',
        component: ()=>import(/* webpackChunkName: "voluntarygroup" */ '../views/VoluntaryGroup.vue')
      },
      {
        path:'/Optimalscheme',
        name:'Optimalscheme',
        component: ()=>import(/* webpackChunkName: "Optimalscheme" */ '../views/Optimalscheme.vue')
      },
      {
        path:'/subjectvoluntary',
        name:'Subjectvoluntary',
        component: ()=>import(/* webpackChunkName: "subjectvoluntary" */ '../views/SubjectVoluntary.vue')
      },
      {
        path:'/Finalscheme',
        name:'Finalscheme',
        component: ()=>import(/* webpackChunkName: "Finalscheme" */ '../views/Finalscheme.vue')
      },
      {
        path:'/historicaldata',
        name:'Historicaldata',
        component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/HistoricalData/HistoricalData.vue')
      },
      {
        path:'/Instructionhome',
        name:'InstructionHome',
        component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/UserInstruction/InstructionHome.vue'),
        children:[
          {
            path:'/workingmanual',
            name:'workingmanual',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/UserInstruction/WorkingManual.vue')
          },
          // {
          //   path:'/CareerIntention',
          //   name:'CareerIntention',
          //   component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/UserInstruction/CareerIntention.vue')
          // },
          {
            path:'/ProfessionalDirection',
            name:'ProfessionalDirection',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/UserInstruction/ProfessionalDirection.vue')
          },
          {
            path:'/voluntaryprinciple',
            name:'voluntaryprinciple',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/UserInstruction/VoluntaryPrinciple.vue')
          },
		  {
		    path:'/Disciplineranking',
		    name:'Disciplineranking',
		    component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/UserInstruction/Disciplineranking.vue')
		  },
		  {
		    path:'/Keydisciplines',
		    name:'Keydisciplines',
		    component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/UserInstruction/Keydisciplines.vue')
		  },
		  {
		    path:'/UniversityDirection',
		    name:'UniversityDirection',
		    component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/UserInstruction/UniversityDirection.vue')
		  }
        ],
      },
	  {
	    path:'/CareerIntentionHome',
	    name:'CareerIntentionHome',
	    component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/UserInstruction/CareerIntentionHome.vue'),
	    children:[
	      {
	        path:'/CareerIntention',
	        name:'CareerIntention',
	        component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/UserInstruction/CareerIntention.vue')
	      },
	      
	    ],
	  },
      {
        path:'/newshome',
        name:'newshome',
        component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/NewsCenter/NewsHome.vue'),
        children:[
          {
            path:'/examnews',
            name:'examnews',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/NewsCenter/ExamNews.vue')
          },
          {
            path:'/videocentercontent',
            name:'videocentercontent',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/NewsCenter/VideoCenterContent.vue')
          },
        ],
      },
      {
        path:'/studyplanhome',
        name:'studyplanhome',
        component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/StudyPlan/StudyPlanHome.vue'),
        children:[
          {
            path:'/nationalstudy',
            name:'nationalstudy',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/StudyPlan/NationalStudy.vue')
          },
          {
            path:'/interstudy',
            name:'interstudy',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/StudyPlan/InterStudy.vue')
          },
          {
            path:'/inspirationaltalents',
            name:'inspirationaltalents',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/StudyPlan/InspirationalTalents.vue'),
            meta:{
              keepAlive: true
            }
          },
          {
            path:'/applicationcases',
            name:'applicationcases',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/StudyPlan/ApplicationCases.vue')
          },
          {
            path:'/academicplanning',
            name:'academicplanning',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/StudyPlan/AcademicPlanning.vue')
          },
        ],
      },
      {
        path:'/exampolicy',
        name:'exampolicy',
        component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/ExamPolicy/ExamPolicyHome.vue'),
        children:[
          {
            path:'/newexam',
            name:'newexam',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/ExamPolicy/NewExam.vue')
          },
          {
            path:'/onescore',
            name:'onescore',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/ExamPolicy/OneScore.vue')
          },
          {
            path:'/paralle',
            name:'paralle',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/ExamPolicy/Paralle.vue')
          },
          {
            path:'/subjectaccept',
            name:'subjectaccept',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/ExamPolicy/SubjectAccept.vue')
          },
          {
            path:'/traditionalexam',
            name:'traditionalexam',
            component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/ExamPolicy/TraditionalExam.vue')
          },
        ],
      },
      {
        path:'/artical',
        component: ()=>import(/* webpackChunkName: "Historicaldata" */ '../views/Artical.vue')
      },
      {
        path:'/problemresolve',
        component: ()=>import(/* webpackChunkName: "problemresolve" */ '../views/ProblemResolve.vue')
      }
    ]
  }
]

const router = new VueRouter({
  routes
})
router.afterEach((to,from)=>{
  //跳转子路由不回到顶部
  if(to.path=="/RegistrationInformation"||to.path=="/videoCenter"||to.path=="/videocentercontent"||to.path=="/examnews"||to.path=="/applicationcases"||to.path=="/inspirationaltalents"||to.path=="/interstudy"||to.path=="/nationalstudy"||to.path=="/academicplanning"){

  }
  else{
    //缓慢回到顶部
    let scrollToptimer = setInterval(function () {
    // console.log("回到顶部")
    var top = document.documentElement.scrollTop;
    if (top!=0) {
      document.documentElement.scrollTop=0;
    }
    if (top == 0) {
      clearInterval(scrollToptimer);
    }
  }, 10); 
  }  
})
//导航守卫
router.beforeEach((to,from,next)=>{
  const username = window.sessionStorage.getItem('username')
  const activeUser = window.sessionStorage.getItem('active_user')
  if(to.path == '/people'||to.path == '/login'||to.path == '/RegistrationInformation'||to.path == '/Home'||to.path =='/Homepage') return next()

  if(!username&&!activeUser){
    next('/Homepage')
  }
  else{
    next();
  }
})
export default router
